<template>
	<view class="home-wrap u-m-b-20">
		<base-nav-bar :isBack="true" :background="{'background':'#fff'}">
			<text
				slot="content"
				style="color: #333; width: 100%; text-align: center;padding-left: 20rpx;"
			>
				活动预约记录
			</text>
		</base-nav-bar>
		<view class="content-box"  v-if="!isEmpty" style="margin-top: 30rpx;">
			<view class="u-flex u-flex-column u-flex-between merchant-box u-m-l-30 u-m-r-30 u-m-b-20" v-for="(item,index) in orderList" :key="index">
				<view class="course-item u-flex u-flex-between u-flex-items-center">
					<view class="he-xiao-status" :class="item.status!='1'?'he-xiao-used':''">
						<view class="he-xiao-status-text">{{item.status=='1'?'未核销':'已核销'}}</view>
					</view>
					<view class="u-flex u-flex-start u-flex-items-center u-flex-3 u-m-l-56 u-p-l-20  u-p-t-20 u-p-b-20">
						<image :src="HTTP_IMG_URL()+item.user.avatar" class="merchant-logo"></image>
						<view class="u-flex u-flex-items-start u-flex-column u-flex-around u-m-l-20" style="height: 140rpx;">
							<view class="course-item-text u-flex u-flex-items-center">
								<view class="u-ellipsis-1" style="width: 20vw">{{ item.user.nickname }}</view>
								<view class="u-ellipsis-1" style="width: 26vw">{{ item.user.mobile }}</view>
							</view>
							<view class="course-item-number">预约时间:{{ item.paytime_text }}</view>
						</view>
					</view>
					<view class="course-item-btn-group u-flex u-flex-1 u-flex-column u-flex-around  u-p-r-20  u-p-t-20 u-p-b-20" v-if="item.status=='1'">
						<view class="course-item-btn edit" @click="jump('/pages-merchant/order/cancelAfterVerification?id='+item.id)">确认核销</view>
						<view class="course-item-btn delete" @click="scanCodeHandler()">扫码核销</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 数据为空 -->
		<u-empty
			v-if="isEmpty"
			mode="data"
			:marginTop="220"
			text="暂无活动预约记录"
		>
		</u-empty>
		<!-- 更多 -->
		<u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc"/>
	</view>
</template>

<script>
let systemInfo = uni.getSystemInfoSync();
let menuButtonInfo = {};
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
menuButtonInfo = uni.getMenuButtonBoundingClientRect();
// #endif
import { mapGetters } from 'vuex';
import { HTTP_IMG_URL } from '../../config/app.js'
import BaseNavBar from "../../components/BaseNavBar.vue";
export default {
	components: {
		BaseNavBar
	},
	data() {
		return {
			activityId:'',
			orderList:[
			],
			loadStatus   : 'nomore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
			currentPage  : 1,
			lastPage     : 1,
			total  : '',
			isEmpty      : false,
		};
	},
	computed: {
		...mapGetters(['isLogin', 'userInfo']),
		customBar() {
			let statusBarHeight = systemInfo.statusBarHeight;
			console.log("====statusBarHeight",statusBarHeight)
			// #ifndef MP
			return systemInfo.platform == 'android' ? statusBarHeight + 50 : statusBarHeight + 45;
			// #endif
			// #ifdef MP-WEIXIN
			return menuButtonInfo.bottom + menuButtonInfo.top - statusBarHeight;
			// #endif
			// #ifdef MP-ALIPAY
			return statusBarHeight + systemInfo.titleBarHeight;
			// #endif
		}
	},
	onPullDownRefresh() {
	
	},
	
	onShow() {
		if(!this.isLogin){
		
		}
		
	},
	onHide() {
	},
	onLoad(options) {
		if(options&&options.id){
			this.activityId = options.id
		}
		this.orderList = [];
		this.currentPage = 1;
		this.getOrderList()
	},
	created() {
		// 触底监听
		uni.$on('uOnReachBottom', data => {
			if (this.loadStatus == 'loadmore') {
				this.currentPage += 1;
				this.getOrderList();
			}
		});
	},
	methods: {
		HTTP_IMG_URL() {
			return HTTP_IMG_URL
		},
		// 路由跳转
		jump(path, parmas) {
			uni.navigateTo({
				url: path,
				query: parmas
			});
		},
		scanCodeHandler	(){
			let that = this;
			// 调起条码扫描
			uni.scanCode({
				onlyFromCamera: true, // 是否只能从相机扫码，不允许从相册选择图片
				scanType: ['qrCode'], // 扫码类型 qrCode二维码
				autoZoom: false, 	  // 是否启用自动放大，默认启用
				success: function (res) {
					console.log(`扫码结果：${JSON.stringify(res,null,2)}`);
					that.parseQRCode(res);
				},
				fail: function (err) {
					console.log(`错误：${err}`);
				},
				complete: function (data) {
					console.log('擦屁股！');
				}
			});
		},
		// 解析二维码，处理业务
		parseQRCode(data){
			uni.vibrateShort();					// 震动提示
			this.jump(data.result)
		},
		// 预约列表
		getOrderList() {
			let that = this;
			that.$Api.merchant.getOrderList({
				status:'1,2',
				activity_id:this.activityId,
				page    : that.currentPage,
				pageSize: 20,
				is_verification:'1'
			}).then(res => {
				console.log("===res",res)
				that.orderList = [...that.orderList, ...res.data.list.data];
				that.isEmpty     = !that.orderList.length;
				that.loadStatus  = that.currentPage < res.data.list.last_page ? 'loadmore' : 'nomore';
			});
		},
	}
};
</script>

<style lang="scss" scoped>
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
.home-wrap {
	min-height: 100vh;
	background: #F6F6F8;
}
.kehu-item {
	border-radius: 20rpx;
	width: 100%;
	.swipers{
		width: 100%;
	}
}
.nickname{
	font-size: 34rpx;
	font-weight: bold;
}
.content-box{
	.merchant-box{
		background:linear-gradient( 180deg, #E8FFED 0%,#FFFFFF 30%, #FFFFFF 100%);
		box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.1), inset 0px 1px 0px 0px #FFFFFF;
		border-radius: 30rpx;
		min-height: 11vh;
		position: relative;
		.course-item{
			width: 100%;
			.he-xiao-status{
				position: absolute;
				left: 0;
				top: 0;
				width: 120rpx;
				height: 100%;
				background: #30AA4D;
				border-radius: 14px 0px 0px 14px;
				display: flex;
				align-items: center;
				justify-content: center;
				.he-xiao-status-text{
					margin-right: 20rpx;
					color: #fff;
					writing-mode: vertical-rl;
					text-align: center;
					letter-spacing: 10rpx; /* 调整字母间距 */
				}
			}
			.he-xiao-used{
				background: rgba(48,170,77,0.3);
			}
			.merchant-logo{
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
			}
			.merchant-icon{
				width: 30rpx;
				height: 30rpx;
			}
			.course-item-text{
				font-weight: 400;
				font-size: 30rpx;
				color: #333;
			}
			.course-item-number{
				font-weight: 400;
				font-size: 13px;
				color: #9A9A9A;
				line-height: 22px;
				text-align: left;
				font-style: normal;
			}
			.course-item-btn-group{
				.course-item-btn{
					width: 78px;
					height: 28px;
					border-radius: 100px;
					display: flex;
					align-items: center;
					justify-content: center;
					font-weight: 500;
				}
				.edit{
					font-size: 28rpx;
					color: #30AA4D;
					background: #EDF7EF;
					border-radius: 22px;
					border: 1px solid #30AA4D;
				}
				.delete{
					margin-top: 20rpx;
					font-size: 28rpx;
					color: #FFB900;
					background: #FFF8E5;
					border-radius: 22px;
					border: 1px solid #FFB900;
				}
			}
		}
		
	}
}
</style>
